Ubuntu Server 2TB Hard Drive Partition and Format Guide
- Fact : I got a newly installed 2TB hard drive on an Ubuntu server.
- Problem : Needs to be partition and formated.
- Hypothese : Using the buildin command like fdisk and mkfs, will be set up with a single partition formatted as ext4.
Prerequisites
A 2TB hard drive installed on the Ubuntu server. Administrative (root) access or sudo privileges.
Steps
1. Identify the New Hard Drive
-
Open a terminal or SSH in your device.
-
Run the following command to list all disk devices:
lsblk
-
Identify the new 2TB drive (e.g.,
/dev/sdb
). It will typically show as unmounted with no partitions or look for the right size. Note the device name (e.g.,/dev/sdb
).Caution: Double-check the device name to avoid accidentally modifying the wrong drive.
2. Partition the Drive
-
Start the
fdisk
utility for the new drive (replace/dev/sdb
with your drive’s device name):sudo fdisk /dev/sdb
-
At the
fdisk
prompt, type the following commands:g
to create a new GPT partition table (suitable for 2TB drives).n
to create a new partition.- Press
Enter
to accept the default partition number (1). - Press
Enter
to accept the default first sector. - Press
Enter
to accept the default last sector (uses the entire drive).
- Press
w
to write the changes and exit. (It might say : The partition table has been altered)
-
Verify the new partition:
lsblk
You should see a new partition (e.g.,
/dev/sdb1
).
3. Format the Partition
- Format the new partition as ext4 (replace
/dev/sdb1
with your partition’s name):sudo mkfs.ext4 /dev/sdb1
- Wait for the formatting to complete (this may take a few minutes).
4. Mount the Drive
- Create a mount point (e.g.,
/mnt/newdrive
):sudo mkdir /mnt/newdrive
- Mount the formatted partition:
sudo mount /dev/sdb1 /mnt/newdrive
- Verify the drive is mounted:
You should see the new drive listed with its mount point.
df -h
5. Configure Automatic Mounting
To ensure the drive mounts automatically on boot:
- Find the UUID of the new partition:
Note the UUID for
sudo blkid /dev/sdb1
/dev/sdb1
(e.g.,1234-5678-9012-3456
). - Edit the
/etc/fstab
file:sudo nano /etc/fstab
- Add the following line at the end of the file (replace
UUID
with your partition’s UUID):/dev/disk/by-uuid/1234-5678-9012-3456 /mnt/newdrive ext4 defaults 0 2
- Save and exit (
Ctrl+O
,Enter
,Ctrl+X
). - Test the
fstab
configuration:If no errors appear, the configuration is correct.sudo mount -a
6. Set Permissions (Optional)
To allow a specific user or group to access the drive:
- Change ownership (replace
username
with the desired user):sudo chown -R username:username /mnt/newdrive
- Adjust permissions as needed:
sudo chmod -R 755 /mnt/newdrive
Verification
- Check the drive’s status:
lsblk
df -h - Ensure you can read/write to the mount point:
touch /mnt/newdrive/testfile
ls /mnt/newdrive